package com.example.sms;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class Sms_Receiver  extends BroadcastReceiver {


	@Override
    public void onReceive(Context context, Intent intent) {
    	Bundle bundle = intent.getExtras();
    	intent.setClass(context, popup_window.class);
    	// get the SMS received
    	Object[] pdus = (Object[]) bundle.get("pdus");
    	SmsMessage[] msgs = new SmsMessage[pdus.length];

    	for (int i=0; i<msgs.length; i++){
    	      msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
    	      
    	      Toast toast = Toast.makeText(context,"New Message: " + msgs[i].getOriginatingAddress() + " " +
    	      msgs[i].getDisplayMessageBody() + " " + msgs[i].getTimestampMillis(), Toast.LENGTH_LONG);
      		toast.show();
      		// cal popup_window class
      		
    	}
	
    }

}
